package com.wenlin.customerservice.domain;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;

public class ValidateCustomerBNet {
public static void main(String[] args) {
		
//		String apiUrl = "http://58.32.246.71:8000/getWaybillCountNew.action";// 测试
		String clientId = "K99902155";
		String ytoappkey= "mdmoutbase";	
		String apiUrl = "http://10.129.220.223:8001/customer/date?"+"customerCode=" + clientId; //本地
		Long timeStamp = (System.currentTimeMillis())/1000;
		
		String parternId = "576D7DAA489EB18F";

			
		try {
			
			//打开连接
			URL url = new URL(apiUrl);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			MessageDigest messagedigest = MessageDigest.getInstance("MD5");
			String toSign = "/customer/date?"+"customerCode=" + clientId;
			String sign =Test.MD5(toSign+parternId);
			System.out.println(sign);
			connection.setRequestProperty("ytoappkey", "mdmoutbase");
			connection.setRequestProperty("timestamp",String.valueOf(timeStamp));
			//d42cfea021ccdf42624e2bdf1e158661
			connection.setRequestProperty("sign", sign);
//			connection.setDoOutput(true);
//			connection.setRequestMethod("GET");
//			OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
			//数据
//			String jsonString = "{\"customerCode\":\"K99902155\"}";			
			//加密
			
//			messagedigest.update((xmlBuilder + parternId).getBytes("UTF-8"));
//			byte[] abyte0 = messagedigest.digest();
//			String data_digest = new String(Base64.encodeBase64(abyte0));
			//查询.

//			System.out.println(data_digest);
//			String queryString = "ytoappkey=" + URLEncoder.encode(ytoappkey, "UTF-8")
//					+ "&timestamp=" + URLEncoder.encode(String.valueOf(timeStamp),"UTF-8")
//					+ "&sign="+ URLEncoder.encode(sign,"UTF-8");
//			out.write(queryString);
//			out.flush();
//			out.close();
			//获取服务端的反馈
			String responseString = "";
			String strLine = "";
			InputStream in = connection.getInputStream();
			BufferedReader reader = new BufferedReader(new InputStreamReader(in));
			while ((strLine = reader.readLine()) != null) {
				responseString += strLine + "\n";
			}
			in.close();
			System.err.print("请求的返回信息："+responseString);
		} catch(Exception e){
			e.printStackTrace();
		}
	

	}
}
